package com.trust;

import com.trust.mapper.PartyMemberMapper;
import com.trust.pojo.PartyMember;
import com.trust.util.SqlSessionUtil;
import org.apache.ibatis.session.SqlSession;

import javax.crypto.spec.PSource;
import java.util.ArrayList;
import java.util.Date;

public class MyBatisDL {
    public static void main(String[] args) {
        //获取sqlSession
        SqlSession s = SqlSessionUtil.getSqlsession();
        PartyMemberMapper mapper = s.getMapper(PartyMemberMapper.class);
        //输出表中成员个数
        int count = mapper.count();
        System.out.println(count);

        //展示party_member表中所有数据
        //showAllInfo(mapper);

        //输出某个成员的信息
        //selectPartyMember("胡建军");

        // 创建新党员对象
        PartyMember newMember = new PartyMember();

        newMember.setMemberName("张三");
        newMember.setMemberGender('M');
        newMember.setMemberBirth(new Date());

        int i = mapper.insertPartyMember(newMember);
        s.commit();
        s.close();
    }
    public static void selectPartyMember(String partymember){
        SqlSession s = SqlSessionUtil.getSqlsession();
        PartyMemberMapper mapper = s.getMapper(PartyMemberMapper.class);
        PartyMember name = mapper.getPartyMemberByName(partymember);
        System.out.println(name);

    }
    public static void showAllInfo(PartyMemberMapper mapper){
        ArrayList<PartyMember> list = new ArrayList<>();
        for (int i = 11; i < 26; i++) {
            PartyMember partyMemberById = mapper.getPartyMemberById(i);
            //System.out.println(partyMemberById);
            list.add(partyMemberById);
        }
        System.out.println("\n===== 党员详细信息 =====");
        for (PartyMember member : list) {
            System.out.println("ID: " + member.memberId);
            System.out.println("姓名: " + member.memberName);
            System.out.println("性别: " + member.memberGender);
            System.out.println("身份证: " + member.memberIdcard);
            System.out.println("手机号: " + member.memberMobile);
            System.out.println("入党日期: " + member.joinPartyDate);
            System.out.println("党内职务: " + member.partyPosition);
            System.out.println("状态: " + member.memberStatus);
            System.out.println("----------------------");
        }
    }
}
